import config from "@/config";
import qs from 'qs' // qs在安装axios后会自动安装，只需要组件里import一下即可
import http from "@/utils/request";

export default {
	// 分页查询线索报名表
	list: {
		url: `${config.API_URL}/college/visitor/page`,
		name: "数据列表",
		get: async function (params) {
			return await http.post(this.url, params);
		},
	},
	detail: {
		url: `${config.API_URL}/college/visitor/findDetail`,
		name: "数据详情",
		get: async function (params) {
			return await http.get(this.url, params);
		},
	},
	// 新增线索报名表
	add: {
		url: `${config.API_URL}/college/visitor`,
		name: "新增线索",
		get: async function (params) {
			console.log(params);
				const formData = new FormData();
				Object.keys(params).forEach(key => {
					if (typeof params[key] == "string" || typeof params[key] == "number") {
						formData.append(key, params[key]);
					} else {
						params[key].forEach((item,index) => {
							Object.keys(item).forEach(keys => {
								var name = key+"["+[index]+"]."+ [keys];
								formData.append(name, item[keys]);
							})
						})
					}
				});
			return await http.post(this.url,  formData,{
				'Content-type':'multipart/form-data'
			});
		},
	},
	// 批量分配线索
	batchAllocation: {
		url: `${config.API_URL}/college/visitor/batchAllocation`,
		name: "批量分配",
		post: async function (params) {
			return await http.post(this.url, params);
		},
	},
	// 删除线索报名
	delete: {
		url: `${config.API_URL}/college/visitor/delete`,
		name: "删除线索",
		post: async function (params) {
			return await http.post(this.url, params);
		},
	},
	// 修改线索报名
	update: {
		url: `${config.API_URL}/college/visitor/update`,
		name: "修改线索",
		post: async function (params) {
			const formData = new FormData();
			Object.keys(params).forEach(key => {
				console.log(typeof params[key])
				if (typeof params[key] == "string" || typeof params[key] == "number") {
					formData.append(key, params[key]);
				} else {
					console.log(params[key])
					if(params[key]){
						params[key].forEach((item,index) => {
							Object.keys(item).forEach(keys => {
								var name = key+"["+[index]+"]."+ [keys];
								formData.append(name, item[keys]);
							})
						})
					}
				}
			});
			return await http.post(this.url, formData,{
				'Content-type':'multipart/form-data'
			});
		},
	},
	// 获取校区列表【下拉框选择时可用】
	dropdown: {
		url: `${config.API_URL}/college/school/dropdown`,
		name: "获取校区列表【下拉框选择时可用】",
		get: async function (params) {
			return await http.get(this.url, params);
		},
	},
};
